/************** init.html **************/
function queryOrgan_organ(page) {
	var parm = $('#queryOrganForm').serialize() + sys_get_page(page);
	var url = create_url('organ-query');
	sys_record_parm('organ', parm);
	sys_loading();
	sys_record_parm('organ',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#organResultList').html(result);
		}
	});
}

function deleteOrgan_organ(code, name) {
	var url = create_url('organ-delete');
	aidExecuteOrgan_organ(code, url);
}

function shieldOrgan_organ(code, name) {
	$.Zebra_Dialog('确定是否屏蔽'+name,{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
           {caption:'屏蔽',callback:function() {
        	   var url = create_url('organ-shield');
   				aidExecuteOrgan_organ(code, url);
    		}},
           {caption:'取消',callback:function(){}
    	}]
	});
}

function unshieldOrgan_organ(code, name) {
	$.Zebra_Dialog('确认要解除 ' + name + ' 机构的屏蔽状态吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
           {caption:'解除',callback:function() {
        	   var url = create_url('organ-unshield');
   				aidExecuteOrgan_organ(code, url);
    		}},
           {caption:'取消',callback:function(){}
    	}]
	});
}

function aidExecuteOrgan_organ(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				new sys_msg('操作成功');
				queryOrgan_organ();
			} else {
				new sys_msg('操作失败');
				queryOrgan_organ();
			}
		}
	});
}

function selectParent_organ() {
	var url = create_url('organ-aidQueryInit');
	var parm = {'id':'parentCode', 'name':'parentName'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}

function loadSonList_organ(code) {
	var url = create_url('organ-sonList');
	var parm = {'code':code};
	var sonTd = $('#orgaSonTd_' + code);
	sonTd.html(sys_loading_img);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sonTd.html(result);
		}
	});
}

function editOrgan_organ(code, parentCode) {
	var url = create_url('organ-edit');
	var parm = {'code':(null != code ? code : ''), 'parentCode':(null != parentCode ? parentCode : '')};
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			$('#editOrganTd').html(result);
		}
	});
}


/************** edit.html **************/
function saveOrgan_organ() {
	var parm = $('#editOrganForm').serialize();
	var url = create_url('organ-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				queryOrgan_organ();
			} else {
				sys_msg('操作失败');
				queryOrgan_organ();
			}
		}
	});
}

function selectParent_organ(code) {
	var url = create_url('organ-aidInit');
	var parm = {'id':'pc', 'name':'pn', 'code':code};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'400px', height:'600px', open:true});
}


function saveOrganization_organ() {
	$('#name').val(), $('#address').val(), $('#phone').val(), $('#manager').val()
		var parm = $('#editOrganizationForm').serialize();
		var url = '${contextPath}organ-saveSelf.html?time=' + getTime();
		sys_submiting();
		$.ajax({type:'POST', url:url, data:parm,
			success: function(result) {
				sys_submiting_close();
				if (result == 'success') {
					sys_msg('操作成功!');
				} else {
					sys_warning('操作失败!');
				}
			}
		});
	}

//显示地图和隐藏地图
function show_organ(){
	var xs = $("#show");
	if(xs.is(":hidden")){
			$("#crawl").show();
			xs.show();
			loadScript_organ();
		}else{
			$("#crawl").hide()
			xs.hide();
		} 
}
//异步加载
function loadScript_organ() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://webapi.amap.com/maps?v=1.2&key=yourkey&callback=init_organ";
	document.body.appendChild(script);
}

function clickGetPoints_organ(ls,ln){
	map.clearMap();
	marker = new AMap.Marker({     
     });     
	marker.setMap(map); 
	marker.setPosition(new AMap.LngLat(parseFloat(ls),parseFloat(ln)));
}

function crawlPoint_organ(){
	var lo = $("#lo").val();  
	var la = $("#la").val(); 
	$("#longitude1").val(lo);  
	$("#latitude1").val(la); 
}